/**
 * 
 */
package org.t2.game.server.module.recharge.api;

import java.util.ArrayList;
import java.util.List;

import org.gaming.tool.GsonUtil;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.t2.design.module.RechargeTable;
import org.t2.design.module.autogen.RechargeAbstractTable.RechargeCfg;

import sh.t2.share.apiutil.GameApi;
import sh.t2.share.module.recharge.RechargeApiProtocol.RechargeCfgRequest;
import sh.t2.share.module.recharge.RechargeApiProtocol.RechargeCfgResponse;
import sh.t2.share.module.recharge.RechargeCfgForm;

/**
 * @author YY
 *
 */
@Controller
public class RechargeProductCfgApi {
	
	
	@RequestMapping(value = GameApi.rechargeProductCfgUpdate)
	@ResponseBody
	public RechargeCfgResponse update(@RequestBody RechargeCfgRequest request) {
		List<RechargeCfgForm> list = new ArrayList<>();
		for(RechargeCfg cfg : RechargeTable.ins().all()) {
			RechargeCfgForm form = new RechargeCfgForm();
			form.setId(cfg.getId());
			form.setName(cfg.getName());
			form.setType(cfg.getType());
			form.setPrice(cfg.getPrice());
			form.setObtainNum(GsonUtil.toJson(cfg.getObtainNum()));
			list.add(form);
		}
		
		RechargeCfgResponse response = new RechargeCfgResponse();
		response.rechargeCfgs = list;
		return response;
	}
}
